/*
 * 文件名：PushCarOutBillInfoRunble.java	 
 * 时     间：下午7:16:04
 * 作     者：Administrator       
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.local.manager.push;

import java.util.List;

import com.cz073586.message.websocket356.push.PushManager;
import com.cz073586.message.websocket356.transfer.TransferVo;
import com.local.entity.webpush.CarInPushVo;
import com.local.model.Crossing;
import com.local.model.LocalStation;
import com.local.service.face.CrossingService;
import com.qianhai.common.utils.Log4jUtil;
import com.qianhai.common.utils.Tools;

/**
 * 类描述: 推送车出场计费信息.
 * 
 * @ClassName: PushCarOutBillInfoRunble
 * @author Administrator
 * @date 2015年9月29日 下午7:16:04
 */
public class PushCarInBillInfoRunble implements Runnable
{
	
	private static Log4jUtil log = Log4jUtil
			.getLog4j(PushCarInBillInfoRunble.class);
	
	private CrossingService crossinService;
	
	private CarInPushVo carInpushVo;
	
	public PushCarInBillInfoRunble(CrossingService crossinService,
			CarInPushVo carInpushVo)
	{
		super();
		this.crossinService = crossinService;
		this.carInpushVo = carInpushVo;
	}
	
	@Override
	public void run()
	{
		
		try
		{
			
			// 通过设备编码查询路口数 这些查询需要放入线程里。TODO 张威
			List<Crossing> crossList = crossinService
					.queryCrossingByEquimentNo(carInpushVo.getEuqmentNo());
			
			if (crossList.isEmpty())
			{
				return;
			}
			// 通过路口数查询需要推送多少个岗亭
			List<LocalStation> stationList = crossinService
					.queryStaionsByCrosList(crossList);
			carInpushVo.setStationList(stationList);
			
			if (!Tools.isEmpty(crossList) && !crossList.isEmpty())
			{
				carInpushVo.setRoadName(crossList.get(0).getName());
				carInpushVo.setRoadUuid(crossList.get(0).getUuid());
			}
			
			String stute = carInpushVo.getIsOpenGate().equals("1") ? "已开"
					: "未开";
			// 组装最终显示信息
			carInpushVo.setPageShow(carInpushVo.getCarNoTye() + " ["
					+ carInpushVo.getCarNo() + "]" + ",从  "
					+ carInpushVo.getRoadName() + "驶入!!!  闸机状态[" + stute + "]");
			
			TransferVo<CarInPushVo> trans = new TransferVo<CarInPushVo>();
			trans.setEventType("carIn");
			trans.setData(carInpushVo);
			
			PushManager.instance().pushMessage(trans);
		} catch (Throwable t)
		{
			log.error("", t);
		}
	}
	
}
